package com.youku.plugins.endcardV4New.view
{
   import flash.display.Sprite;
   import com.youku.interfaces.IEndCardV4New;
   import com.youku.plugins.PluginEventDispather;
   import com.youku.baseUI.BasePlayerButton;
   import flash.text.TextField;
   import com.youku.plugins.endcardV4New.model.data.PlayerSizeData;
   import flash.events.MouseEvent;
   import com.youku.plugins.endcardV4New.EndCardEvent;
   import com.youku.utils.ReportUtil;
   import com.youku.utils.AssetUtil;
   import com.youku.plugins.endcardV4New.EndCardFont;
   import flash.text.TextFieldAutoSize;
   
   public class TouchFullScreen extends Sprite implements IEndCardV4New
   {
      
      public function TouchFullScreen() {
         super();
      }
      
      private var _eventManger:PluginEventDispather;
      
      private var _onButton:BasePlayerButton;
      
      private var _offButton:BasePlayerButton;
      
      private var _titleOn:TextField;
      
      private var _titleOff:TextField;
      
      private var _sizeData:PlayerSizeData;
      
      private function addEvents() : void {
         this._onButton.addEventListener(MouseEvent.CLICK,this.onButtonOnTap);
         this._offButton.addEventListener(MouseEvent.CLICK,this.onButtonOffTap);
      }
      
      private function onButtonOnTap(param1:MouseEvent) : void {
         this._eventManger.dispatchEvent(new EndCardEvent(EndCardEvent.ENDCARD_FULLSCREEN_TAP));
         ReportUtil.sendUserActionLog(ReportUtil.TOUCH_ENDCARD_ENTER_FULLSCREEN,ReportUtil.METHOD_TOUCH_TAP);
      }
      
      private function onButtonOffTap(param1:MouseEvent) : void {
         this._eventManger.dispatchEvent(new EndCardEvent(EndCardEvent.ENDCARD_FULLSCREEN_TAP));
         ReportUtil.sendUserActionLog(ReportUtil.TOUCH_ENDCARD_QUIT_FULLSCREEN,ReportUtil.METHOD_TOUCH_TAP);
      }
      
      public function changeSize(param1:PlayerSizeData = null) : void {
         if(param1.isFullScreen)
         {
            this._onButton.visible = false;
            this._offButton.visible = true;
         }
         else
         {
            this._onButton.visible = true;
            this._offButton.visible = false;
         }
      }
      
      public function init(param1:Object = null, param2:PluginEventDispather = null, param3:PlayerSizeData = null) : void {
         this._eventManger = param2;
         this._sizeData = param3;
         this._onButton = AssetUtil.getStyleButton("EndCard_fullScreen_on");
         AssetUtil.restoreButtonSize(this._onButton);
         addChild(this._onButton);
         this._offButton = AssetUtil.getStyleButton("EndCard_fullScreen_off");
         AssetUtil.restoreButtonSize(this._offButton);
         addChild(this._offButton);
         this._titleOn = AssetUtil.getTextField(false);
         this._titleOn.defaultTextFormat = EndCardFont.FONT_INTERACTION_COMMON;
         this._titleOn.autoSize = TextFieldAutoSize.LEFT;
         this._titleOn.text = "全屏";
         this._titleOn.x = 43;
         this._titleOn.y = 11;
         this._onButton.addChild(this._titleOn);
         this._titleOff = AssetUtil.getTextField(false);
         this._titleOff.defaultTextFormat = EndCardFont.FONT_INTERACTION_COMMON;
         this._titleOff.autoSize = TextFieldAutoSize.LEFT;
         this._titleOff.text = "退出";
         this._titleOff.x = 43;
         this._titleOff.y = 11;
         this._offButton.addChild(this._titleOff);
         this.addEvents();
         this.changeSize(this._sizeData);
      }
      
      private function removeEvent() : void {
         this._onButton.removeEventListener(MouseEvent.CLICK,this.onButtonOnTap);
         this._offButton.removeEventListener(MouseEvent.CLICK,this.onButtonOffTap);
      }
      
      public function uninstall() : void {
         this.removeEvent();
         if(contains(this._onButton))
         {
            removeChild(this._onButton);
         }
         if(contains(this._titleOn))
         {
            removeChild(this._titleOn);
         }
         if(contains(this._offButton))
         {
            removeChild(this._offButton);
         }
         if(contains(this._titleOff))
         {
            removeChild(this._titleOff);
         }
      }
   }
}
